package com.example.aigc_education.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.aigc_education.common.BusinessException;
import com.example.aigc_education.domain.Todo;
import com.example.aigc_education.service.TodoService;
import com.example.aigc_education.mapper.TodoMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 23918
* @description 针对表【stu_todo(任务清单)】的数据库操作Service实现
* @createDate 2024-05-29 22:25:50
*/
@Service
public class TodoServiceImpl extends ServiceImpl<TodoMapper, Todo>
    implements TodoService{
    @Resource
    private TodoMapper todoMapper;



    @Override
    @Transactional
    public void addTodo(Todo todo){
        try {
            todoMapper.insert(todo);
        }catch (Exception e){
            throw new BusinessException("添加任务清单失败");
        }
    }


    @Override
    @Transactional
    public void updateTodoById(Todo todo, Long id){
        try {
            todo.setTodoId(id);
            todoMapper.updateById(todo);

        }catch (Exception e){
            throw new BusinessException("更新任务清单失败");
        }
    }


    @Override
    @Transactional
    public void deleteTodoById(Long id){
        try {
            todoMapper.deleteById(id);
        }catch (Exception e){
            throw new BusinessException("删除任务清单失败");
        }
    }



    @Override
    public List<Todo> getAllTodo(){
        try {
            return todoMapper.selectList(null);
        }catch (Exception e){
            throw new BusinessException("查询任务清单列表失败");
        }
    }

}




